Conversation
|
Since this changes the return format, I do not want to put this in 5.0.x but it is OK to put in main |
f1b2108 to
0e58e3a
Compare
|
Retargeted to main and rebased onto d4d8148 (0e58e3a). Re-ran on that base: reverting only MatrixVariableParameterProcessor leaves the two added tests failing (SpringMvcContractTests:832 and :840) with the rest of the 71 passing; with the change, |
|
Please sign your commit so the DCO passes |
MatrixVariableParameterProcessor built the path segment from the raw toString() of each value, so a collection came out bracketed: ;colours=[red, blue] instead of ;colours=red,blue. A matrix variable separates repeated values with a comma, so the receiving side reads "[red" and " blue]" back out of the bracketed form. Both branches of the processor were affected, including the Map<String, List<String>> signature used as the @MatrixVariable example in the reference documentation. Signed-off-by: kdelay <kdelay20@gmail.com>
0e58e3a to
bd2b41f
Compare
| assertThat(";param=value").isEqualTo(data.indexToExpander().get(0).expand(testMap)); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Can we add a test through a real Feign client and/or RestTemplate? I believe RequestTemplateFactoryResolver.expandElements() will add a , in the result as well
|
|
||
| private String expandValue(Object value) { | ||
| if (value instanceof Collection<?> values) { | ||
| return values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining(",")); |
There was a problem hiding this comment.
I think you can use org.springframework.util.StringUtils.collectionToCommaDelimitedString
Use StringUtils.collectionToCommaDelimitedString for the join and flatten arrays and nested collections through the same path. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in 4bb1784: join via You are right about |
No, IMO we should deal with it as part of this change |
Feign pct-encodes every value it substitutes into a URI template, so the ';' and '=' produced by the expander left the segment as %3Bname%3Dvalue and the server could not read it as matrix variables. Move the ';name=' prefix into the URI template, where it survives as a literal, and let the expander produce only the value. A collection parameter is expanded element by element by Feign and joined with ',', which now yields ';colours=red,blue'. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in 02fbad7. Feign pct-encodes every value substituted into a URI template, so the separators came out as Measured through a stub Arrays (not
|
| } | ||
|
|
||
| private String expandValue(Object value) { | ||
| if (value.getClass().isArray()) { |
There was a problem hiding this comment.
I don't think the Map-typed @MatrixVariable case case is handled properly
Let Feign expand a Map typed matrix variable through a path-style URI template expression, so the ; and = separators stay literal in the request URL and only the keys and the values are encoded. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in 94a9ad3: the Collection-valued entries are still not covered: |
|
Shouldn't |
|
Measured on feign-core 13.14 through a stub That output needs a Feign-side change to path-style expansion. Open it upstream and keep this PR to the cases it covers, or drop the map change? |
|
Thanks for the explaination. Lets drop the Map coverage for now and file the bug upstream in Feign. |
Feign encodes each value of a path-style expression, so a collection valued map entry cannot keep its separators. Leave map expansion as it was and keep this change to the cases it covers. Signed-off-by: kdelay <kdelay20@gmail.com>
|
Done in f404d40: map expansion and its tests are back to what they are on
I will open the path-style expansion bug with Feign and link it here. |
MatrixVariableParameterProcessorbuilds the path segment from each value'stoString(), so a collection comes out bracketed:@MatrixVariable("colours") List<String>ofred,bluegives;colours=[red, blue]. A matrix variable separates repeated values with a comma, soWebUtils.parseMatrixVariablesreads that as{colours=[[red, blue]]}and;colours=red,blueas{colours=[red, blue]}. Values are now joined with a comma; arrays and nested values take the same path.Feign also pct-encodes values substituted into a URI template. The
;name=prefix now sits in the template and stays literal: through a stubClientaStringparam was%3Bparam%3Dvalue, now;param=value.Mapvariables are unchanged; a collection-valued entry needs a fix in Feign's path-style expansion.verify: 448 tests, 0 failures.